/*******************************************************************************
 * Copyright 2020 huanggefan.cn
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/

package main

import (
	"flag"

	"gitee.com/WisdomClassroom/cli/action"
	"gitee.com/WisdomClassroom/cli/glb"
	"gitee.com/WisdomClassroom/core"
)

func main() {
	core.PublicFlag(BuildTag, BuildGo, BuildTime)
	flag.StringVar(&glb.TitleName, "chapter-name", "", "chapter name")
	flag.StringVar(&glb.Description, "chapter-description", "", "chapter description")
	flag.IntVar(&glb.ManagerUUID, "chapter-manager", 0, "chapter manager account id")
	flag.StringVar(&glb.OfCourseUUID, "chapter-course", "", "chapter of course, uuid")
	flag.IntVar(&glb.ChapterIndex, "chapter-index", 1, "chapter index")
	flag.Parse()

	if core.FlagHelp {
		flag.Usage()
		return
	}
	if core.FlagVersion {
		core.PublicVersion()
		return
	}
	if !core.FlagUseSqlite && !core.FlagUsePG {
		flag.Usage()
		return
	}

	glb.Logger = core.NewLogger(core.FlagLogLevel)

	if core.FlagUseSqlite {
	} else if core.FlagUsePG {
	} else {
		flag.Usage()
		return
	}

	if uuid := action.ChapterCreate(); uuid == "" {
		glb.Logger.Info("Create Chapter failed")
	} else {
		glb.Logger.Info("Create Chapter successfully: " + uuid)
	}
}
